# 设计一个类
class Student:
    name = None
    gender = None
    nationality = None
    native_place = None
    age = None


# 创建一个对象
stu_1 = Student()

# 给对象赋值
stu_1.name = "张三"
stu_1.gender = "男"
stu_1.nationality = "中国"
stu_1.native_place = "广东省"
stu_1.age = 31

print(stu_1.name)
print(stu_1.gender)
print(stu_1.nationality)
print(stu_1.native_place)
print(stu_1.age)


# 成员方法
class Stu:
    name = None

    def say_hi(self):
        print(f"你好,我的名字是{self.name}")

    def say_hi2(self, msg):
        print(f"你好,其实我不是{self.name},{msg}")


stu_2 = Stu()
stu_2.name = "李四"
stu_2.say_hi()
stu_2.say_hi2("我是马鹿")


class Clock:
    id = None
    price = None

    def ring(self):
        import winsound
        winsound.Beep(2000, 3000)  # 频率, 时间


clock1 = Clock()
clock2 = Clock()
clock1.id = "00321"
clock1.price = 19.99
# clock1.ring()


# 内置方法(魔术方法)
# 构造方法  __init__()
class St:
    # 变量可以不写出来
    # name = None
    # gender = None

    def __init__(self, name, gender):
        # 此时的name和gender是声明并赋值
        self.name = name
        self.gender = gender


stu_3 = St("王五", "女")


# 字符串方法 __str__()
# 小于符号比较方法 __lt__()
# 带等于比较方法使用 __le__()
# 等于符号比较方法 __eq__()
# 使用返回值
class St2:
    name = None
    age = None

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def __str__(self):
        return f"name = {self.name}\nage = {self.age}"

    def __lt__(self, other):
        return self.age < other.age

    def __le__(self, other):
        return self.age <= other.age

    # 没有写__eq__()方法, 对两个对象进行==比较时默认比较对象的地址, 基本返回False
    def __eq__(self, other):
        return self.age == other.age


stu_4 = St2("赵六", 33)
print(stu_4)
stu_5 = St2("老七", 44)
print(stu_4 < stu_5)
print(stu_4 > stu_5)
print(stu_4 <= stu_5)
print(stu_4 >= stu_5)
print(stu_4 == stu_5)
